﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ChatClientApp.Classes;
using ChatClientApp.Tools;

namespace ChatClientApp.GUI
{
    public partial class fContactDelete : Form
    {
        public fContactDelete()
        {
            InitializeComponent();
            foreach (string nick in Tools.ActiveComponents.ActiveUser.Contacts)
                listBox1.Items.Add(nick); 
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex != -1)
            {
                listBox2.Items.Add(listBox1.SelectedItem);
                listBox1.Items.RemoveAt(listBox1.SelectedIndex);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (listBox2.SelectedIndex != -1)
            {
                listBox1.Items.Add(listBox2.SelectedItem);
                listBox2.Items.RemoveAt(listBox2.SelectedIndex);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (listBox2.Items.Count == 0)
                return;

            List<string> listToDelete = new List<string>();

            for (int i = 0; i < listBox2.Items.Count; i++)
            {
                listToDelete.Add(listBox2.Items[i].ToString());
                Tools.ActiveComponents.ActiveUser.Contacts.Remove(listBox2.Items[i].ToString());
            }

            ServerHandling.RemoveContacts(Tools.ActiveComponents.ActiveUser.Nick, listToDelete);
            this.Close();
        }
    }
}
